package net.huashitong.ssydt;

import java.io.Serializable;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2018.01.15
 */
public class PaginationQuery implements Serializable {

    private static final long serialVersionUID = 5995028579744057629L;

    /**
     * 读取记录数
     */
    private int pageSize;
    /**
     * 当前页
     */
    private int pageNumber;
    /**
     * 行偏移
     */
    private int pageRowOffset;

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
        calcRowOffset();
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        if (pageNumber < 1) {
            pageNumber = 1;
        }
        this.pageNumber = pageNumber;
        calcRowOffset();
    }

    public int getPageRowOffset() {
        return pageRowOffset;
    }

    void setPageRowOffset(int pageRowOffset) {
        this.pageRowOffset = pageRowOffset;
    }

    private void calcRowOffset() {
        if (pageNumber > 0 && pageSize > 0) {
            pageRowOffset = pageNumber * pageSize - pageSize;
        }
    }

    @Override
    public String toString() {
        return "PaginationQuery{" +
                "pageSize=" + pageSize +
                ", pageNumber=" + pageNumber +
                ", pageRowOffset=" + pageRowOffset +
                '}';
    }
}
